package com.qf09;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class MyList {
    //创建锁
    private Lock lock=new ReentrantLock();
    private String[] str={"A","B","","",""};
    private int count=2;

    public void add(String value){
        lock.lock();
        try{
            str[count]=value;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            count++;
        }finally {
            lock.unlock();
        }
    }

    public String[] getStr() {
        return str;
    }
}
